package com.saumya.robotlegs.view
{
	import com.saumya.robotlegs.events.LoggerEvent;
	
	import flash.events.MouseEvent;
	
	import org.robotlegs.mvcs.Mediator;

	public class LoggerViewMediator extends Mediator
	{
		[Inject]
		public var loggerView:LoggerView;
		
		public function LoggerViewMediator()
		{
			//Does Nothing
		}
		
		public override function onRegister():void
		{
			//listen to context
			this.eventMap.mapListener(this.eventDispatcher,LoggerEvent.UPDATE_LOG,onUpdateLogEvent,LoggerEvent);
			//listen to view
			this.eventMap.mapListener(this.loggerView.clearLogBtn,MouseEvent.CLICK,onClearClick,MouseEvent);
		}
		
		private function onClearClick(e:MouseEvent):void
		{
			this.loggerView.clearLog();
		}
		
		private function onUpdateLogEvent(e:LoggerEvent):void
		{
			var message:String=e.getLogMessage();
			var shouldHilight:Boolean=e.getHilightOption();
			this.loggerView.log(message,shouldHilight);
		}
	}
}